package com.wcity.manage.common.context;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
 * spring上下文
 * 
 * @author dy
 *
 */
public class SpringContext implements ApplicationContextAware {
	
	private final static Logger log = LoggerFactory.getLogger( SpringContext.class.getName() );

	private static ApplicationContext applicationContext;

	public void setApplicationContext( ApplicationContext applicationContext ) throws BeansException {
		SpringContext.applicationContext = applicationContext;
	}
	
	public static ApplicationContext getApplicationContext() {
		
		if ( applicationContext == null ) {
			log.error( "[applicationContext]未初始化" );
		}
		return applicationContext;
	}
	
	public Object getBean( String className ) {
		
		if ( applicationContext == null ) {
			log.error( "[applicationContext]未初始化" );
		}
		return applicationContext.getBean( className );
	}

}
